<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/hexo-blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/hexo-blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/hexo-blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/hexo-blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/hexo-blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/hexo-blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/hexo-blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="如果你对算法不感兴趣，或者那你根本看不懂算法，这本书非常适合你了。">
<meta property="og:type" content="article">
<meta property="og:title" content="《啊哈！算法》读书感悟">
<meta property="og:url" content="https://son9wx.gitee.io/hexo-blog/aha-algorithm/index.html">
<meta property="og:site_name" content="son9wxのblog">
<meta property="og:description" content="如果你对算法不感兴趣，或者那你根本看不懂算法，这本书非常适合你了。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/ey*Vc3C6GMsPipkedfOC5CRVSo1S8Mg7XzUErk*XbWo!/r/dD4BAAAAAAAA">
<meta property="og:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/Yg6JKlzdBRjrqgxsvfJn4Kllut0WIUMWnxYRpz3yXMQ!/r/dFMBAAAAAAAA">
<meta property="og:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/KvJNUhZ.Vrp5sF4lZKXUV3rZbGdjO32GfAKToFNDScA!/r/dFQBAAAAAAAA">
<meta property="og:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/k4PZdLqqpy7GPZemCg458LhCqntI5cUT96A6r*s58eU!/r/dEcBAAAAAAAA">
<meta property="og:updated_time" content="2018-11-13T11:34:09.202Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="《啊哈！算法》读书感悟">
<meta name="twitter:description" content="如果你对算法不感兴趣，或者那你根本看不懂算法，这本书非常适合你了。">
<meta name="twitter:image" content="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/ey*Vc3C6GMsPipkedfOC5CRVSo1S8Mg7XzUErk*XbWo!/r/dD4BAAAAAAAA">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/hexo-blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://son9wx.gitee.io/hexo-blog/aha-algorithm/">





  <title>《啊哈！算法》读书感悟 | son9wxのblog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/hexo-blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">son9wxのblog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/hexo-blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/hexo-blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/hexo-blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/hexo-blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://son9wx.gitee.io/hexo-blog/hexo-blog/aha-algorithm/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="son9wx">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/hexo-blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="son9wxのblog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">《啊哈！算法》读书感悟</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-12T20:39:29+08:00">
                2018-11-12
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/ey*Vc3C6GMsPipkedfOC5CRVSo1S8Mg7XzUErk*XbWo!/r/dD4BAAAAAAAA" alt="cover"></p>
<blockquote>
<p>如果你对算法不感兴趣，或者那你根本看不懂算法，这本书非常适合你了。  </p>
</blockquote>
<a id="more"></a>
<h1 id="桶排序"><a href="#桶排序" class="headerlink" title="桶排序"></a>桶排序</h1><p>想象一下，你有一堆小于十的数字，你应该怎么快速将他们拍好顺序呢？<br>如果你有十个桶，你是否可以把这些数字数字分别装在桶里？<br>下面这个算法，就描述了怎么进行排序！<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">sort</span><span class="params">(<span class="keyword">int</span> *arr)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">while</span>(len(arr))</span><br><span class="line">    b[*(arr++)]++;</span><br><span class="line">  <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><img src="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/Yg6JKlzdBRjrqgxsvfJn4Kllut0WIUMWnxYRpz3yXMQ!/r/dFMBAAAAAAAA" alt="桶排序"><br>但是，这时数组中来了一个怪物，他竟突是999;<br>虽然只来了一个999但是我们需要额外增加990个桶去存储这个怪物。<br>你也看到了，桶排序太占用空间了！下面看一种不费空间的排序，冒泡！  </p>
<h1 id="冒泡排序"><a href="#冒泡排序" class="headerlink" title="冒泡排序"></a>冒泡排序</h1><p>我们从小到大排序，对数组扫描时，相邻元素位置错误，就直接交换。<br>如果你不理解你可以想象一下，你在拍摄毕业照，照相时让同学们相邻两个两个相互调换是不是这个原理呢？<br>下面这个算法，就描述了怎么进行排序！<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">sort</span><span class="params">(<span class="keyword">int</span> *arr)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i&lt;=len(arr);i++)</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">1</span>; j&lt;=len(arr)<span class="number">-1</span>;j++)</span><br><span class="line">      <span class="keyword">if</span>(!*(arr+j)&lt;*(arr+j+<span class="number">1</span>))</span><br><span class="line">        swap(arr+j,arr+j+<span class="number">1</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><img src="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/KvJNUhZ.Vrp5sF4lZKXUV3rZbGdjO32GfAKToFNDScA!/r/dFQBAAAAAAAA" alt="冒泡排序"><br>或许是这个算法过于平庸，人们总是在尝试找到一款非常特殊的算法，它的运行时间是非常快速的！<br>下面我们看一下拿过诺贝尔奖的排序  </p>
<h1 id="快速排序"><a href="#快速排序" class="headerlink" title="快速排序"></a>快速排序</h1><p>对于一个已经排好序的数组来说，区道中间数，他的左边总是小于他，他的右边总是大于他，这个就是我们期望看到的。<br>我们选取一个数，让他的左边总是小于这个数，右边总是大于这个数，当指针会合的时候，我们把选取的数移动到那个位置，对于子部，我们重复上面步骤！<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">sort</span><span class="params">(<span class="keyword">int</span> *arr,<span class="keyword">int</span> l,<span class="keyword">int</span> r)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">if</span>(l&gt;r)</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">  <span class="keyword">int</span> i = l;</span><br><span class="line">  <span class="keyword">int</span> j = r;</span><br><span class="line">  <span class="keyword">int</span>* n = arr+l;</span><br><span class="line">  <span class="keyword">while</span>(i!=j)</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="keyword">while</span>(!((*(arr+j))&lt;*n)&amp;&amp;i&lt;j)</span><br><span class="line">      j--;</span><br><span class="line">    <span class="keyword">while</span>(!((*(arr+i))&gt;*n)&amp;&amp;i&lt;j)</span><br><span class="line">      i++;</span><br><span class="line">    <span class="keyword">if</span>(i&lt;j)</span><br><span class="line">    Swap(arr+i,arr+j);</span><br><span class="line">  &#125;</span><br><span class="line">  Swap(n,arr+i);</span><br><span class="line">  Sort(arr,l,i<span class="number">-1</span>);</span><br><span class="line">  Sort(arr,i+<span class="number">1</span>,r);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><img src="https://r.photo.store.qq.com/psb?/V146EW4F0E6ZOW/k4PZdLqqpy7GPZemCg458LhCqntI5cUT96A6r*s58eU!/r/dEcBAAAAAAAA" alt="快速排序"></p>
<p>11.12更新第一章 </p>
<p>注意： 部分代码可能会和作者书上源代码有出入，一些是在理解的基础上自己敲出来的 @好吧，大多数都是！ </p>
<h1 id="队列"><a href="#队列" class="headerlink" title="队列"></a>队列</h1><p>想象一下，我们在排队结束超市的购物，先排队的人先结账出去了，后排队的后结账出去了。这是一种队列的数据结构，它的特点是先进先出。在本章中的第一个问题是解密QQ号，细细分析一下，可解性，队列出两个，入一个？取出队的队列作为答案。因为数据结构在c++STL中都已经实现了，现在我用这种STL这种方式去实现一下，这道题比较简单！</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Solution</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="built_in">queue</span>&lt;<span class="keyword">int</span>&gt; q_init = &#123;<span class="number">6</span>,<span class="number">3</span>,<span class="number">1</span>,<span class="number">7</span>,<span class="number">5</span>,<span class="number">8</span>,<span class="number">9</span>,<span class="number">2</span>,<span class="number">4</span>&#125;;</span><br><span class="line">  <span class="keyword">int</span> num = <span class="number">9</span>;</span><br><span class="line">  <span class="built_in">queue</span>&lt;<span class="keyword">int</span>&gt; q_new;</span><br><span class="line">  <span class="keyword">while</span> (!q_init.empty())</span><br><span class="line">  &#123;</span><br><span class="line">    q_new.push(q_init.front());</span><br><span class="line">    q_init.pop();</span><br><span class="line">    q_init.push(q_init.front());</span><br><span class="line">    q_init.pop();</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= num; i++)</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; q_new.front();</span><br><span class="line">    q_new.pop();</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="栈"><a href="#栈" class="headerlink" title="栈"></a>栈</h1><p>栈的一个典型的应用就是判断回文数了，形如12321这样，当然，我们去想为了实现这样的数字，我们只需要取前一半12，1先进2后进，对比后面再输入的2和1.那么作为奇数位的3我们不需要考虑。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">Solution</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">char</span> *str = <span class="string">"ahaha\0"</span>;</span><br><span class="line">  <span class="keyword">int</span> mid = <span class="built_in">strlen</span>(str) / <span class="number">2</span>;</span><br><span class="line">  <span class="built_in">stack</span>&lt;<span class="keyword">char</span>&gt; s;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= mid; i++)</span><br><span class="line">    s.push(str[i]);</span><br><span class="line">  <span class="keyword">if</span> (<span class="built_in">strlen</span>(str) % <span class="number">2</span> == <span class="number">0</span>)</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= mid; i++)</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="keyword">char</span> pd = s.top();</span><br><span class="line">      s.pop();</span><br><span class="line">      <span class="keyword">if</span> (pd != str[mid + <span class="number">1</span> - i])</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">else</span></span><br><span class="line">  &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= mid; i++)</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="keyword">char</span> pd = s.top();</span><br><span class="line">      s.pop();</span><br><span class="line">      <span class="keyword">if</span> (pd != str[mid * <span class="number">2</span> + <span class="number">1</span> - i])</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>我这样写过于复杂了，因为if和else存在大量重复的代码，其实我们只需要在<code>if (pd != str[mid * 2 + 1 - i])</code>中做一个判断，使奇数偶数有差别即可，也可以向上取整，这样最后就成为一种情况了，奇数中 str[mid]和str[mid]肯定是相等的。你可以都去实现以下，我因为没有过大脑就写代码，这里告诉我们，写算法是一定要在心里过一遍！</p>
<h1 id="小猫钓鱼"><a href="#小猫钓鱼" class="headerlink" title="小猫钓鱼"></a>小猫钓鱼</h1><p>一个经典的扑克游戏，虽然我没玩过，我大概说一下思路，首先我们需要发牌，并规定牌的顺序@太不智能了吧，可能这是一本关于新手的算法书，我们需要两个队列，一个栈，我们去分析游戏过程，再打出牌的时候，先判断牌堆中是否有你打出的牌，有的话你需要收牌，没有你的牌加入牌堆，过程很简单，我这里给出我的代码，没有书上那么啰嗦，思路较强！</p>
<pre><code class="C"><span class="function"><span class="keyword">void</span> <span class="title">Solution</span><span class="params">()</span></span>
<span class="function"></span>{
    <span class="built_in">queue</span>&lt;<span class="keyword">int</span>&gt; player1;
    <span class="built_in">queue</span>&lt;<span class="keyword">int</span>&gt; player2;
    <span class="built_in">stack</span>&lt;<span class="keyword">int</span>&gt; gamepool;
    <span class="keyword">bool</span> book[<span class="number">6</span>];
    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++)
    {
        <span class="keyword">int</span> cardnumber;
        <span class="built_in">cin</span> &gt;&gt; cardnumber;
        player1.push(cardnumber);
    }
    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++)
    {
        <span class="keyword">int</span> cardnumber;
        <span class="built_in">cin</span> &gt;&gt; cardnumber;
        player2.push(cardnumber);
    }
    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++)
    {
        book[i] = <span class="number">0</span>;
    }
    <span class="keyword">while</span>(!player2.empty()&amp;&amp;!player1.empty())
    {
        <span class="keyword">if</span>(book[player1.front()])
        {
            <span class="keyword">while</span>(book[player1.front()])
            {
              <span class="keyword">int</span> card = gamepool.top();
              book[card] = <span class="number">0</span>;
              gamepool.pop();
              player1.push(card);
            }
        }
        <span class="keyword">else</span>
        {
            gamepool.push(player1.front());
            book[player1.front()
            ] = <span class="number">1</span>;
            player1.pop();
        }

        <span class="keyword">if</span>(book[player2.front()])
        {
            <span class="keyword">while</span>(book[player2.front()])
            {
              <span class="keyword">int</span> card = gamepool.top();
              book[card] = <span class="number">0</span>;
              gamepool.pop();
              player2.push(card);
            }
        }
        <span class="keyword">else</span>
        {
            gamepool.push(player2.front());
            book[player2.front()] = <span class="number">1</span>;
            player2.pop();
        }
    }
    <span class="keyword">if</span>(player2.empty())
        <span class="built_in">cout</span>&lt;&lt;<span class="string">"player1 win"</span>&lt;&lt;<span class="built_in">endl</span>;
    <span class="keyword">if</span>(player1.empty())
        <span class="built_in">cout</span>&lt;&lt;<span class="string">"player2 win"</span>&lt;&lt;<span class="built_in">endl</span>;
}
</code></pre>
<p>代码中涉及到数据结构的代码均使用STL，将问题关注到解决问题的思路中，之后的问题中，可能有的问题需要我们再去使用一些其他非典型数据结构，我会给出实现的，但是现阶段，最好将算法应用到成熟的数据结构中！</p>
<p>11.13更新第二章</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/hexo-blog/time-manage-method/" rel="next" title="事件管理-你的清单正常吗？">
                <i class="fa fa-chevron-left"></i> 事件管理-你的清单正常吗？
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/hexo-blog/prim-algorithm/" rel="prev" title="算法 - 最小生成树">
                算法 - 最小生成树 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">son9wx</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/hexo-blog/archives/">
              
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#桶排序"><span class="nav-number">1.</span> <span class="nav-text">桶排序</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#冒泡排序"><span class="nav-number">2.</span> <span class="nav-text">冒泡排序</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#快速排序"><span class="nav-number">3.</span> <span class="nav-text">快速排序</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#队列"><span class="nav-number">4.</span> <span class="nav-text">队列</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#栈"><span class="nav-number">5.</span> <span class="nav-text">栈</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#小猫钓鱼"><span class="nav-number">6.</span> <span class="nav-text">小猫钓鱼</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">son9wx</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/hexo-blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/hexo-blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/hexo-blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/hexo-blog/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/hexo-blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/hexo-blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/hexo-blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
